﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Text.RegularExpressions;

namespace Expressionista
{
	public class SavedSettings
	{
		public string RegexStr
		{
			get;
			set;
		}

		public RegexOptions RegexOptions
		{
			get;
			set;
		}

		public string Source
		{
			get;
			set;
		}

		public void Save(string filepath)
		{
			using (StreamWriter sw = new StreamWriter(filepath))
			{
				XmlSerializer xs = new XmlSerializer(this.GetType());
				xs.Serialize(sw, this);
			}
		}

		public static SavedSettings Load(string filepath)
		{
			if (!File.Exists(filepath))
			{
				return null;
			}

			using (StreamReader sr = new StreamReader(filepath))
			{
				XmlSerializer xs = new XmlSerializer(typeof(SavedSettings));
				return xs.Deserialize(sr) as SavedSettings;
			}
		}
	}
}
